<?php

namespace CMBUBank\UBank\Request\TransManager;

use CMBUBank\UBank\Info\TransManager\Payee;
use CMBUBank\UBank\Request\UBankBaseRequest;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitRefundResponse;

class TransManagerSubunitRefundRequest extends UBankBaseRequest
{
    protected $code = 'NTOPRDMR';

    protected $response = TransManagerSubunitRefundResponse::class;

    protected $logTip = '记账子单元退款经办';

    private $busMode;

    private $backNo;

    private $account;

    private $subCode;

    /**
     * @var Payee $payee
     */
    private $payee;

    public function generate(): array
    {
        $param = [
            'ntbusmody' => [[
                'busmod' => $this->busMode
            ]],
            'ntoprdmrx1' => [[
                'bbknbr' => $this->backNo,
                'accnbr' => $this->account,
                'dumnbr' => $this->subCode,
                'eptdat' => date('Ymd'),
                'intflg' => 'N',
                'intamt' => '0',
                'yurref' => $this->newReqCode()
            ]],
            'ntoprdmrx2' => [[
            ]]
        ];

        $param['ntoprdmrx1'][0] += $this->payee->refund();
        $param['ntoprdmrx2'][0] += $this->payee->refund2();

        return $param;
    }

    public function setBusMode($busMode): void
    {
        $this->busMode = $busMode;
    }

    public function setBackNo($backNo): void
    {
        $this->backNo = $backNo;
    }

    public function setAccount($account): void
    {
        $this->account = $account;
    }

    public function setSubCode($subCode): void
    {
        $this->subCode = $subCode;
    }

    /**
     * @param Payee $payee
     */
    public function setPayee(Payee $payee): void
    {
        $this->payee = $payee;
    }
}